#include "Color.h"
#include"agk.h"
#include<cmath>

Color::Color()
{
	r = g = b = 0;
}

Color::Color(float r, bool isInt)
{
	if (isInt)
	{
		this->SetInt(r, r, r);
	}
	else
	{
		this->SetFloat(r, r, r);
	}
}

Color::Color(float r, float g, float b, bool isInt)
{
	if (isInt)
	{
		this->SetInt(r, g, b);
	}
	else
	{
		this->SetFloat(r, g, b);
	}
}


Color::~Color()
{
}

int Color::GetValue()
{
	return agk::MakeColor(GetIntR(), GetIntG(), GetIntB());
}

int Color::GetIntR()
{
	r = COLOR_NORMALIZE_F(r);
	return COLOR_I(r);
}

int Color::GetIntG()
{
	g = COLOR_NORMALIZE_F(g);
	return COLOR_I(g);
}

int Color::GetIntB()
{
	b = COLOR_NORMALIZE_F(b);
	return COLOR_I(b);
}

float Color::GetFloatB()
{
	return COLOR_NORMALIZE_F(b);
}

float Color::GetFloatR()
{
	return COLOR_NORMALIZE_F(r);
}

float Color::GetFloatG()
{
	return COLOR_NORMALIZE_F(g);
}

void Color::SetFloat(float r, float g, float b)
{
	//r = COLOR_NORMALIZE_F(r);
	//g = COLOR_NORMALIZE_F(g);
	//b = COLOR_NORMALIZE_F(b);
	this->r = r;
	this->g = g;
	this->b = b;
}

void Color::SetInt(int r, int g, int b)
{
	this->r = COLOR_F(r);
	this->g = COLOR_F(g);
	this->b = COLOR_F(b);
}

Color operator*(float k, Color c)
{
	Color res;
	res.SetFloat(k*c.r, k*c.g, k*c.b);
	return res;
}

Color operator*(Color c, float k)
{
	return k * c;
}

Color operator/(Color c, float k)
{
	Color res;
	res.SetFloat(c.r / k, c.g / k, c.b / k);
	return res;
}

Color operator+(Color c1, Color c2)
{
	Color res;
	res.SetFloat(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
	return res;
}

Color operator-(Color c1, Color c2)
{
	Color res;
	res.SetFloat(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b);
	return res;
}

Color operator*(Color c1, Color c2)
{
	Color res;
	res.SetFloat(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b);
	return res;
}

void operator+=(Color & c1, Color c2)
{
	c1.SetFloat(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
}

void operator-=(Color & c1, Color c2)
{
	c1.SetFloat(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b);
}

bool operator==(Color & c1, Color c2)
{
	if (abs(c1.r - c2.r) < 1e-5 && abs(c1.g - c2.g) < 1e-5 && abs(c1.b - c2.b) < 1e-5)
	{
		return true;
	}
	return false;
}

bool operator!=(Color & c1, Color c2)
{
	if (abs(c1.r - c2.r) > 1e-5 || abs(c1.g - c2.g) > 1e-5 || abs(c1.b - c2.b) > 1e-5)
	{
		return true;
	}
	return false;
}
